import { defineStore } from "pinia";
import { SessionStorage } from "@/utils/storage"; //getItem和setItem是封装的操作localStorage的方法

export const CATEGORIES = "ylmall_regions";

export const finAllRegionList = defineStore("region", {
  state: () => ({
    // 分类缓存数据
    categories: SessionStorage.getItem(CATEGORIES) || []
  }),
  actions: {
    getCategories() {
      return this.categories;
    },
    saveCategories(categories) {
      if (categories == null) return;
      this.categories = JSON.parse(categories);
      SessionStorage.setItem(CATEGORIES, categories);
    },
    removeCategories() {
      this.categories = [];
      SessionStorage.removeItem(CATEGORIES);
    }
  }
});
